/********************************************************************
*Copyright (C) 2011,China CQU EasyBoard Team.
*All rights reserved.
*
*File Name:connectsocket.cpp
*File ID  :
*Summary  :this file declares all the basic informations of the user
*in order to maintain the information during one session
*
*Version  :1.0.0
*Author   :YaoBoYuan
*Date     :2011-5-28
********************************************************************/

#include "connectsocket.h"

ConnectSocket::ConnectSocket(QObject *parent) :
    QTcpSocket(parent)
{

    connect(this,SIGNAL(connected()),this,SLOT(processConnected()));
    connect(this,SIGNAL(disconnected()),this,SLOT(processDisconnect()));
    connect(this,SIGNAL(readyRead()),this,SLOT(processReadyRead()));
    connect(this,SIGNAL(readChannelFinished()),this,SLOT(processReadChannelFinished()));
    connect(this,SIGNAL(bytesWritten(qint64)),this,SLOT(processBytesWritten(qint64)));
    connect(this,SIGNAL(aboutToClose()),this,SLOT(processAboutToClose()));
}

/*******************************************************************
 *Summary:
 *Input  :
 *Output :
 *return :
 *******************************************************************/
void ConnectSocket::processReadyRead()
{
    int header_len = sizeof(m_header);

    QByteArray header;
    QByteArray data;

    header = read(header_len); //read the msgheader
    memcpy(&m_header,header.data(),header_len); //move the content to the

    data = read(m_header.len); //read the message content depend on the len
    emit newData(m_header,data); //emit the data the the reciver
}
void ConnectSocket::sendPackage(QByteArray package)
{
    write(package);
}

/*******************************************************************
 *Summary:
 *Input  :
 *Output :
 *return :
 *******************************************************************/
void ConnectSocket::processBytesWritten(qint64 bytes)
{

}
/*******************************************************************
 *Summary:
 *Input  :
 *Output :
 *return :
 *******************************************************************/
void ConnectSocket::processConnected()
{

}
/*******************************************************************
 *Summary:
 *Input  :
 *Output :
 *return :
 *******************************************************************/
void ConnectSocket::processDisconnect()
{

}
/*******************************************************************
 *Summary:
 *Input  :
 *Output :
 *return :
 *******************************************************************/
void ConnectSocket::processReadChannelFinished()
{

}
/*******************************************************************
 *Summary:
 *Input  :
 *Output :
 *return :
 *******************************************************************/
void ConnectSocket::processAboutToClose()
{

}
